<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   
   <%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>注册</title>
<link rel="stylesheet" type="text/css" href="/text2/css/styles.css">
</head>
<body>
<div class="wrapper">

	<div class="container">
		<h1>租客注册</h1>
		<form class="form" id="loginform" method="post">
			<div><input type="text" name="username" placeholder="请输入用户名" ></div>
			<div><input type="password" name="password" placeholder="请输入密码" ></div>
			<div><input type="password" name="password2" placeholder="请输入确认密码" ></div>
		<div>
			<a  href="/text2/login.jsp" style="text-align:right;color:#fff">已有账号？点击登录</a>
		</div>
        
			<button type="submit" id="login-button">注册</button>
		</form>
	</div>
	
	<ul class="bg-bubbles">
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
	</ul>
	
</div>

<script type="text/javascript" src="/text2/js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/text2/js/jquery.validate.min.js"></script>
<script type="text/javascript"
    src="/text2/js/localization/messages_zh.js"></script>
<script type="text/javascript">
$(function() {
	var f=true;
	var f2=true;
	//注册信息验证
	$("input[name='password'],input[name='password2']").blur(function(){
		var flag =true;
		var flag2=true;
		var username=$("input[name='username']").val();
		var password=$("input[name='password2']").val();
		var repassword=$("input[name='password2']").val();
		if(username==""){
			flag=flag && false;
		}
		if(password=="")
			flag=flag && false;
			
		if(repassword==""){
			flag=flag && false;
		} 
		f=flag;
		if(repassword!=password){
			flag2=flag2 && false;
		}
		f2=flag2;
		
	});
	
	
	//为注册按钮绑定点击注册时间  出发regist方法
	$("#login-button").click(function(){
		if(!f){
			alert("用户名或密码不能为空！")
		}else if(!f2){
			alert("两次密码不一致！")
		}else{ 
			return regist();
		}
	});
})

function regist(){
	var username=$("input[name='username']").val();
	var password=$("input[name='password2']").val();
	
	$.ajax({
		url:"/text2/regist.action",
		data:{userName:username,passWord:password},
		type:"post",
		async: false,
		success:function(data){
			var flag=data.success;
			if(flag){
				alert("恭喜您注册成功！");
				window.location.href = "/text2/login.jsp";
			}else{
				var msg=data.msg;
				alert(msg);
			}
		}
	})
}
</script>
</body>
</html>